<template>
  <div>
    <!--新增/修改-弹窗  -->
    <el-dialog title="停用员工" :visible.sync="dialogProp.visible" :close-on-click-modal="false" @opened="listenOpenedDialog" @closed="listenClosedDialog">

      <el-form ref="dialogFormData" :model="dialogFormData" label-width="160px" :rules="dialogFormDataRules">
        <el-form-item label="已选员工：" prop="ids">
          <div class="user-box">
            <div v-for="(item,index) in selectUserLlist" :key="item.id" class="user-item clearfix">
              <div class="item-left">
                <span class="item-chName">{{ item.chName }}</span>
                <span class="item-orgName">{{ item.orgName }} / {{ item.roleName }}</span>
              </div>
              <div class="item-right text-center">
                <span class="item-icon el-icon-close" @click="deleteItem(index)" />
              </div>
            </div>

          </div>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="dialogProp.visible = false">取消</el-button>
        <el-button type="primary" @click="dialogFormDataSubmit('dialogFormData')">立即提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { batchDisable } from '@/api/api'

export default {
  name: 'UserStopUse',
  props: {
    // 弹窗属性相关数据(必传)
    dialogProp: {
      type: Object,
      default: null
    },
    // 用户信息(必传)
    userList: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      // 所选数据
      selectUserLlist: [],

      // 表单数据
      dialogFormData: {
        ids: ''
      },
      // 表单数据验证
      dialogFormDataRules: {
        // ids: [
        //   { required: true, message: '没有选择需要修改的员工', change: 'blur' }
        // ]

      }
    }
  },
  methods: {

    listenOpenedDialog() {
      this.selectUserLlist = this.Utils.deepCopy(this.userList)
      this.dialogFormData.ids = this.Utils.getTreeDataIDList(this.selectUserLlist, 'userId')
    },
    listenClosedDialog() {
      this.$refs['dialogFormData'].resetFields()
      this.Utils.emptyObject(this.dialogFormData)
    },
    deleteItem(index) {
      this.selectUserLlist.splice(index, 1)
    },
    // 新增编辑弹窗表单提交
    dialogFormDataSubmit(formName) {
      this.dialogFormData.ids = this.Utils.getTreeDataIDList(this.selectUserLlist, 'userId')

      if (this.dialogFormData.ids && this.dialogFormData.ids.length) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const params = this.Utils.deepCopy(this.dialogFormData)

            batchDisable(params).then(res => {
              if (res.code === '0000') {
                this.$message({
                  message: res.msg,
                  type: 'success'
                })
                this.dialogProp.visible = false
                this.$emit('getTableList', false)
              }
            })
          } else {
            return false
          }
        })
      } else {
        this.$message.error('没有选择需要修改的员工')
        return
      }
    }

  }
}
</script>
<style lang="scss" scoped>
.user-box{
  border: 1px solid #ebeef5;
  padding:10px;
  height: 200px;
  overflow-y: auto;
  .user-item{
    height: 30px;
    line-height: 30px;
    border-bottom: 1px solid #ebeef5;
    .item-left{
      width: 85%;
      float: left;
      span{
        display: inline-block;
        width:49%;
      }
      .item-chName{
        width:35%;
      }
      .item-orgName{
        width:64%;
      }
    }
    .item-right{
      width: 14%;
      float: right;
      .item-icon{
        font-size: 20px;
        font-weight: bold;
        cursor: pointer;
        color:#F56C6C;
      }
      .item-icon:hover{
        color:#20a0ff;
      }
    }
  }
}

</style>
